package com.lz.util;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class SystemParsUtils {
    
    private static SystemParsUtils systemParsUtils;
    
    private Context thisContext;
    
    private SharedPreferences sharedPreferences;
    
    private Editor editor;
    
    /** 定义存储的唯一Key,扩展时在此加Key */
    public static final String KEY_ISAUTOLOGIN = "isAutoLogin";
    
    public static final String KEY_KSDATE = "ksdate";
    
    public static final String KEY_JSDATE = "jsdate";
    
    public static final String KEY_FSDATE = "fsdate";
    
    public static final String KEY_DXCONTENT = "dxcontent";
    
    public static final String KEY_ISLOGIN = "islogin";
    
    public static final String KEY_ADVERSION = "adversion";
    
    public static final String SOUND = "sound";
    
    public static final String KEY_ISDWTXL = "isdwtxl";
    
    public static final String KEY_ISDWTXLIS = "isdwtxlis";
    
    public static final String KEY_LOCAL_SERVICE = "localservice";
    
    /************************************************************************
     * 构造函数
     * */
    private SystemParsUtils(Context context) {
        thisContext = context;
        sharedPreferences = thisContext.getSharedPreferences("systempars", Activity.MODE_PRIVATE);
        editor = sharedPreferences.edit();
    }
    
    /**
     * 获取本类唯一实例
     * */
    public static SystemParsUtils getInstance(Context context) {
        if (systemParsUtils == null) {
            systemParsUtils = new SystemParsUtils(context);
        }
        return systemParsUtils;
    }
    
    /**
     * 获取Boolean类型数据
     * */
    public boolean getBoolean(String key) {
        return sharedPreferences.getBoolean(key, false);
    }
    
    /**
     * 获取Boolean类型数据,默认返回True 仅用于登录成功后,获取登录设置
     * */
    public boolean getBooleanDefaultTrue(String key) {
        return sharedPreferences.getBoolean(key, true);
    }
    
    /**
     * 获取Float类型数据
     * */
    public float getFloat(String key) {
        return sharedPreferences.getFloat(key, 0);
    }
    
    /**
     * 获取Int类型数据
     * */
    public int getInt(String key) {
        return sharedPreferences.getInt(key, 0);
    }
    
    public int getInt(String key, int defaultValue) {
        return sharedPreferences.getInt(key, defaultValue);
    }
    
    /**
     * 获取Long类型数据
     * */
    public long getLong(String key) {
        return sharedPreferences.getLong(key, 0);
    }
    
    /**
     * 获取String类型数据
     * */
    public String getString(String key) {
        return sharedPreferences.getString(key, "");
    }
    
    /**
     * 设置Boolean类型数据
     * */
    public void setBoolean(String key, boolean value) {
        editor.putBoolean(key, value).commit();
    }
    
    /**
     * 设置Float类型数据
     * */
    public void setFloat(String key, float value) {
        editor.putFloat(key, value).commit();
    }
    
    /**
     * 设置Int类型数据
     * */
    public void setInt(String key, int value) {
        editor.putInt(key, value).commit();
    }
    
    /**
     * 设置Long类型数据
     * */
    public void setLong(String key, long value) {
        editor.putLong(key, value).commit();
    }
    
    /**
     * 设置String类型数据
     * */
    public void setString(String key, String value) {
        editor.putString(key, value).commit();
    }
    
}
